<?php

class t_integration extends CodeIgniterUnitTestCase {

     private $service_url = 'http://localhost/services-hotels/ibookhotelrest/hotel/';

     public function __construct() {

          parent::__construct('Test Home Page');

          $this->load->library('rest', array(
              'server' => $this->service_url
          ));
          $this->load->library('rest_utility');
     }

     public function setUp() {
          
     }

     public function tearDown() {
          
     }

     // home page is visited
     public function test_visitor_visits_home_page_var_1_1() {

          $result = $this->rest->post("popular_destination");

          $this->assertTrue($this->rest_utility->verify($result));

          $this->assertTrue(!empty($result->destinations) && !empty($result->most_viewed) && !empty($result->special_offer));
     }

     // search from home page and hotel-list page is with same data - same tests
     public function test_visitor_preform_search___FullData_var_2_1() {

          $GET = array(
              'destination_hotel' => "a",
              'check_in' => "21.12.2012",
              'check_out' => "22.12.2012",
              'nr_adults' => "1",
              'nr_childrens' => "1",
              'ages' => array(3)
          );

          $result = $this->rest->post("search", $GET);

          $this->assertTrue($this->rest_utility->verify($result));
     }

     // search with no specific dates are the same as clicking on destination name link
     public function test_visitor_preform_search___NoSpecificDates_var_2_2() {

          $GET = array(
              'destination_hotel' => "a"
          );

          $result = $this->rest->post("search_preview", $GET);

          $this->assertTrue($this->rest_utility->verify($result));
     }

     // this is clickon destination object type
     public function test_visitor_preform_search___NoSpecificDatesByObjectType_var_2_3() {

          $GET = array(
              'destination_hotel' => "a",
              'object_type' => "accommodation"
          );

          $result = $this->rest->post("search_preview", $GET);

          $this->assertTrue($this->rest_utility->verify($result));

          foreach ($result as $hotel):

               $this->assertFalse($hotel->object_type_type == 'hotel');

          endforeach;

          //$this->dump($result);
     }

     // this is clickon destination object type
     public function test_visitor_preform_search___NoSpecificDatesByObjectType_var_2_4() {

          $GET = array(
              'destination_hotel' => "a",
              'object_type' => "hotel"
          );

          $result = $this->rest->post("search_preview", $GET);

          $this->assertTrue($this->rest_utility->verify($result));

          foreach ($result as $hotel):

               $this->assertTrue($hotel->object_type_type == 'hotel');

          endforeach;

          //$this->dump($result);
     }

     public function test_visitor_preform_sorting___FullData_var_3_1() {

          $GET = array(
              'destination_hotel' => "a",
              'check_in' => "21.12.2012",
              'check_out' => "22.12.2012",
              'nr_adults' => "1",
              'nr_childrens' => "1",
              'ages' => array(3),
              'sort_by' => "recommended"
          );

          $result = $this->rest->post("search", $GET);

          $this->assertTrue($this->rest_utility->verify($result));
     }

     public function test_visitor_preform_sorting___1Adult_var_3_2() {

          $GET = array(
              'destination_hotel' => "a",
              'check_in' => "21.12.2012",
              'check_out' => "22.12.2012",
              'nr_adults' => "1",
              'nr_childrens' => "0",
              'ages' => "",
              'sort_by' => "number_of_stars"
          );

          $result = $this->rest->post("search", $GET);
          
          $this->dump($result);

          $this->assertTrue($this->rest_utility->verify($result));
     }

     public function test_visitor_preform_sortingOnPrice_1Adult_var_3_3() {

          $GET = array(
              'destination_hotel' => "a",
              'check_in' => "21.12.2012",
              'check_out' => "22.12.2012",
              'nr_adults' => "1",
              'nr_childrens' => "0",
              'ages' => "",
              'sort_by' => "price"
          );

          $result = $this->rest->post("search", $GET);

          $this->assertTrue($this->rest_utility->verify($result));

          //$this->dump($result);
     }

     public function test_visitores_view_hotelNoSpecificDates_var_4_1() {

          $GET = array(
              'hotel_id' => 1
          );

          $result = $this->rest->post("details_preview", $GET);

          $this->assertTrue($this->rest_utility->verify($result));

          //$this->dump($result);
     }

     public function test_visitores_view_hotelFullData_var_4_2() {

          $GET = array(
              'hotel_id' => 1,
              'check_in' => "21.12.2012",
              'check_out' => "22.12.2012",
              'nr_adults' => "1",
              'nr_childrens' => "1",
              'ages' => array(1)
          );

          $result = $this->rest->post("details", $GET);

          $this->assertTrue($this->rest_utility->verify($result));

          //$this->dump($result);
     }

     public function test_visitor_click_book_now_CHECKOUT_1_var_5_1() {

          $GET = array(
              'hotel_id' => 1,
              'room_id' => 1,
              'check_in' => "21.12.2012",
              'check_out' => "23.12.2012",
              'nr_adults' => "2",
              'nr_childrens' => "1",
              'ages' => array(1)
          );

          $result = $this->rest->post("show_customer_form", $GET);

          $this->assertTrue($this->rest_utility->verify($result));
     }

     public function test_visitor_click_book_now_CHECKOUT_1_var_5_2() {

          $GET = array(
              'hotel_id' => 1,
              'room_id' => 1,
              'check_in' => "21.12.2012",
              'check_out' => "22.12.2012",
              'nr_adults' => "1",
              'nr_childrens' => "0"
          );

          $result = $this->rest->post("show_customer_form", $GET);

          $this->assertTrue($this->rest_utility->verify($result));
     }

     public function test_visitor_click_continue_checkoutPage2() {

          $GET = array(
              'hotel_id' => 1,
              'room_id' => 1,
              'check_in' => "21.12.2012",
              'check_out' => "22.12.2012",
              'nr_adults' => "1",
              'nr_childrens' => "2",
              'ages' => array(5, 1),
              "firstname" => "firstname",
              "lastname" => "lastname",
              "email" => "email",
              "remarks" => "remarks"
          );

          $result = $this->rest->post("create_reservation", $GET);

          $this->assertTrue($this->rest_utility->verify($result));
     }

      public function test_visitor_click_bookThisRoom_checoutPage2() {

          $GET = array(
              'mobile' => '123',
              'address' => '123',
              'hotel_id' => 1,
              'room_id' => 1,
              'check_in' => "21.12.2012",
              'check_out' => "22.12.2012",
              'nr_adults' => "1",
              'nr_childrens' => "2",
              'ages' => array(5, 1),
              "reservation_id" => 1,
              "cc_type" => "maseterecrad",
              "cc_number" => "1234123412341234",
              "cc_name" => "ivan kukić",
              "cc_month" => "05",
              "cc_year" => "2015",
              "cc_cvc" => "879",
              "conditions" => 1
          );

          $result = $this->rest->post("card_info", $GET);

          $this->assertTrue($this->rest_utility->verify($result));
     }

}

?>